
import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import makeSelectLoading from '../../store/selector/Global'
import { createStructuredSelector } from 'reselect';
import * as globalAction from '../../store/actions/Global'
import PropTypes from 'prop-types'

const mapDispatchToProps = (dispatch) => {
  return bindActionCreators({
    ...globalAction
  }, dispatch)
}

const maStateToProps = () => {
  let newProps = {}
  newProps['loading'] = makeSelectLoading()
  return { ...newProps }
}
const mapStateToProps = createStructuredSelector(maStateToProps());

const connector = connect(mapStateToProps, mapDispatchToProps)

export default class Container extends React.Component {

  static propTypes = {
    component: PropTypes.func.isRequired
  }

  constructor(props) {
    super(props)
    this.Connected = connector(props.component)
  }

  render() {
    let { component, ...otherProps } = this.props
    return <this.Connected {...otherProps} />
  }
}
